package com.southpark.demo.control.commands.config
{
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.southpark.demo.control.commands.BaseCommand;
	import com.southpark.demo.control.events.config.GetConfigSettingsEvent;
	import com.southpark.demo.control.proxies.config.GetConfigSettingsProxy;
	import com.southpark.framework.control.responders.IResponder;


	public class GetConfigSettingsCommand extends BaseCommand
	{
		override public function execute(cairngormEvent:CairngormEvent):void
		{
			var event:GetConfigSettingsEvent = cairngormEvent as GetConfigSettingsEvent;
			var responder:IResponder = new GetConfigSettingsResponder(event.responder);
			var proxy:GetConfigSettingsProxy = new GetConfigSettingsProxy(responder);
			
			proxy.execute();
		}
		
	}
}
	import com.southpark.framework.control.responders.IResponder;
	



//internal responder class
{
	
	import com.southpark.demo.control.responders.BaseResponder;
	import com.southpark.demo.vo.config.LanguageVO;
	import com.southpark.demo.vo.config.ThemeVO;
	
	
	class GetConfigSettingsResponder extends BaseResponder
	{
		
		public function GetConfigSettingsResponder(responder:IResponder)
		{
			super(responder);
		}
		
		override public function onSuccess(result:Object):void
		{
			var xml:XML = result as XML;
			var item:XML;
			
			model.config.configFileVersion = xml.attribute("version");
			
			model.config.isDebugMode = Boolean(int(xml.elements("isDebugMode")));
			model.config.isAutologinMode = Boolean(int(xml.elements("isAutologinMode")));
			model.config.isUnitTestMode = Boolean(int(xml.elements("isUnitTestMode")));
			
			var language:LanguageVO;
			model.config.languages = new Array();
			for each (item in xml.elements("languages").elements("language"))
			{
				language = new LanguageVO;
				language.id = item.attribute("id");
				language.locale = item;
				model.config.languages.push(language);
			};
			
			var theme:ThemeVO;
			model.config.themes = new Array();
			for each (item in xml.elements("themes").elements("theme"))
			{
				theme = new ThemeVO;
				theme.id = item.attribute("id");
				theme.source = item;
				model.config.themes.push(theme);
			};
			
			var isContentStoreActive:Boolean = Boolean(int(xml.elements("contentStore").attribute("active")));
			if (isContentStoreActive)
			{
				model.config.contentStoreURL = xml.elements("contentStore").elements("url");
			};
			
			
			super.onSuccess(result);
		}
		
		
		
	} 
}